package com.atguigu2.two.exer1;

/**
 * ClassName: ArrayExer01
 * Package: com.atguigu2.two.exer1
 * Description:
 *      案例：定义一个int型的一维数组，包含十个元素，分别赋予一些随机的整数，
 *      然后求出所有元素的最大值最小值，综合，并且输出出来
 *
 * @Author BuTang
 * @Create 2023/2/23 13:24
 * @Version 1.0
 */
public class ArrayExer01 {
    public static void main(String[] args) {
        int max = 0;
        int min = 99;
        int[] arr = new  int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random()*100);
            if (arr[i] >= max) {
                max = arr[i];
            }
            if (arr[i] <= min) {
                min = arr[i];

            }
        }
        System.out.println(max);
        System.out.println(min);
    }

    /**
     * ClassName: arrayExer
     * Package: com.atguigu2.two
     * Description:
     *
     * @Author BuTang
     * @Create 2023/2/23 12:36
     * @Version 1.0
     */
    public static class arrayExer {
        //静态初始化
        public static void main(String[] args) {
            int num = 0;
            int[][] arr = new int[][]{{3,5,8},{12,9},{7,0,6,4}};
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr[i].length; j++) {
                    num += arr[i][j];
                }
            }
            System.out.println("总和为"+num);

        }
    }

    /**
     * ClassName: twoArrayTest
     * Package: com.atguigu2.two
     * Description:
     *
     * @Author BuTang
     * @Create 2023/2/23 10:33
     * @Version 1.0
     */
    public static class twoArrayTest {
        public static void main(String argsp[]){
            //静态初始化，数组变量的赋值和数组元素的赋值同时进行
            int[] arr1 = new int[]{1,2,3};
            int[][] arr2 = new int[][]{{1,2,3},{4,5},{6,7,8,9}};

            //动态初始化方式1
            String[][] arr3 = new String[3][4];
            //动态初始化方式2
            String[][] arr4 = new String[3][];
            //arr4接下来如何定义内层数组 ： arr4[0(里面填写内层的哪一个数组)] = new String[];

            //数组内元素的调用
            System.out.println(arr2[0][1]);
            System.out.println(arr2[0]);//这里是调取arr2的地址值
            System.out.println();

            System.out.println(arr4[0]);
            System.out.println(arr4[0][0]);
            System.out.println();

        }
    }
}
